using System;
using System.Drawing;

namespace ICSharpCode.TextEditor.Document
{
	public class FontContainer
	{
		private Font defaultFont;

		private Font regularfont;

		private Font boldfont;

		private Font italicfont;

		private Font bolditalicfont;

		private static float twipsPerPixelY;

		public Font RegularFont => this.regularfont;

		public Font BoldFont => this.boldfont;

		public Font ItalicFont => this.italicfont;

		public Font BoldItalicFont => this.bolditalicfont;

		public static float TwipsPerPixelY
		{
			get
			{
				if (FontContainer.twipsPerPixelY == 0f)
				{
					using Bitmap image = new Bitmap(1, 1);
					using Graphics graphics = Graphics.FromImage(image);
					FontContainer.twipsPerPixelY = 1440f / graphics.DpiY;
				}
				return FontContainer.twipsPerPixelY;
			}
		}

		public Font DefaultFont
		{
			get
			{
				return this.defaultFont;
			}
			set
			{
				float num = (float)Math.Round(value.SizeInPoints * 20f / FontContainer.TwipsPerPixelY);
				this.defaultFont = value;
				this.regularfont = new Font(value.FontFamily, num * FontContainer.TwipsPerPixelY / 20f, FontStyle.Regular);
				this.boldfont = new Font(this.regularfont, FontStyle.Bold);
				this.italicfont = new Font(this.regularfont, FontStyle.Italic);
				this.bolditalicfont = new Font(this.regularfont, FontStyle.Bold | FontStyle.Italic);
			}
		}

		public static Font ParseFont(string font)
		{
			string[] array = font.Split(',', '=');
			return new Font(array[1], float.Parse(array[3]));
		}

		public FontContainer(Font defaultFont)
		{
			this.DefaultFont = defaultFont;
		}
	}
}
